from ability.models import Chapter, Course, StudentCourse
from rest_framework import serializers

class ChapterCreateSerializer(serializers.ModelSerializer):

    course_id = serializers.IntegerField()

    class Meta:
        model = Chapter
        fields = ['chapter_name', 'detail', 'detail_type', 'course_id']

class CourseStudentsSerializer(serializers.ModelSerializer):

    stu_name = serializers.SerializerMethodField()
    choose_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = StudentCourse 
        fields = ['stu_name', 'choose_time', 'stay_sec']

    def get_stu_name(self, obj):
        return obj.student.user.real_name

